package afcp.alumni.model.db;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import afcp.alumni.model.base.DatastoreEntity;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(detachable="true")
public class FileColumn implements DatastoreEntity {
	
//	@Persistent
//	@Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
//	private String mParentEncKey;

	private static final long serialVersionUID = -7218242970300350641L;
	
	@PrimaryKey
	@Persistent
	private Key key;
	// app key
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private String id;
	@Persistent
	@Deprecated
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private String fileColumnName;
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private int position = 0;
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private String label;
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private boolean required;
	public FileColumn() {
		
	}
	public FileColumn(String id, int position, String label) {
		this(id, position, label, false);
	}
	public FileColumn(String id, int position, String label, boolean required) {
		this.id = id;
//		this.fileColumnName = fileColumnName;
		this.position = position;
		this.label = label;
		this.required = required;
	}
	@Override
	public String getId() {
		return id;
	}
	@Override
	public Key getKey() {
		return key;
	}
//	@Override
//	public void setKeyWithAncestor(Key ancestorKey) {
//		this.key = KeyFactory.createKey(ancestorKey, this.getClass().getSimpleName(), id);
//	}
	@Deprecated
	public String getFileColumnName() {
		return fileColumnName;
	}
	@Deprecated
	public void setFileColumnName(String fileColumnName) {
		this.fileColumnName = fileColumnName;
	}

	public int getPosition() {
		return position;
	}
	public void setPosition(int position) {
		this.position = position;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public void setId(String id) {
		this.id = id;
	}
	public boolean isRequired() {
		return required;
	}
	public void setRequired(boolean required) {
		this.required = required;
	}
	
	@Override
	public String toString() {
		return id;
	}
//	@Override
//	public boolean equals(Object obj) {
//		if (!(obj instanceof CsvColumn)) {
//			return false;
//		}
//		CsvColumn col = (CsvColumn) obj;
//		
//		return ;
//	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FileColumn other = (FileColumn) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	protected FileColumn copy() {
		return new FileColumn(id, position, label, required);
	}
}
